package com.feng.show.controller;

import com.alibaba.fastjson.JSONObject;
import com.feng.show.comm.ServerResponse;
import com.feng.show.entity.Agent;
import com.feng.show.entity.RfidData;
import com.feng.show.service.ICountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
统计
 */
@RequestMapping("/count")
@RestController
public class CountController {

    //汇总，几月几日到 几月几日，经销商， 出货数量
    @Autowired
    ICountService countServiceImpl;


   @GetMapping("/getAgent")
    public ServerResponse<List<Agent>>  getConut(
            @RequestParam(value = "userId")   String userId,
            @RequestParam(value = "agent") String agentStr ){

       if(userId==null){
           return ServerResponse.createByErrorMsg("参数错误");
       }
       Agent agent;

       if(agentStr!=null&&agentStr.length()>0){
           agent= JSONObject.parseObject(agentStr,Agent.class);
       }else{
           agent=null;
       }
       return countServiceImpl.searchAllAgent(userId,agent);
    }


    @PostMapping("/getRfid")
    public ServerResponse<List<RfidData>>  getRfids(
            @RequestParam(value = "userId")   String userId,
            @RequestParam(value = "rfidData") String rfidDataStr ) {

        if (userId == null) {
            return ServerResponse.createByErrorMsg("参数错误");
        }

        RfidData rfidData;


        if (rfidDataStr != null && rfidDataStr.length() > 0) {
            rfidData = JSONObject.parseObject(rfidDataStr, RfidData.class);
        } else {
            rfidData = null;
        }
        return countServiceImpl.searchAllRfid(userId, rfidData);
    }

    //






}
